package com.jdz.gxq.info.admin.employment.service;

import java.util.List;
import java.util.Map;

import com.jdz.gxq.info.admin.employment.bo.Employment;

import jp.terasoluna.fw.dao.QueryDAO;
import jp.terasoluna.fw.dao.UpdateDAO;

public class EmploymentServiceImpl implements EmploymentService {
	
	private QueryDAO queryDAO = null;
	
	private UpdateDAO updateDAO = null;
	
	/**
	 * Employment检索分页用，查询记录条数
	 * @return
	 */
	public int getEmploymentsCount(String enterpriseName) {
		
		int totalCount = queryDAO.executeForObject("employment.getEmploymentsCount",
				enterpriseName, Integer.class);
		
		return totalCount;
	}
	
	/**
	 * Employment检索
	 * @return
	 */
	public List<Employment> getEmployments(Map<String, Object> params) {
		
		return queryDAO.executeForObjectList("employment.getEmployments", params);
	}
	
	/**
	 * 追加Employment
	 * @param employment
	 */
	public void insertEmployment(Employment employment) {
		
		updateDAO.execute("employment.insertEmployment", employment);
	}
	
	/**
	 * 更新Employment
	 * @param employment
	 */
	public void updateEmployment(Employment employment) {
		
		updateDAO.execute("employment.updateEmployment", employment);
	}
	
	/**
	 * 通过id得到employment
	 * @param id
	 * @return
	 */
	public Employment getEmploymentById(int id) {

		Employment employment = queryDAO.executeForObject("employment.getEmploymentById",
				id, Employment.class);
		
		return employment;
	}
	
	/**
	 * 删除Employment
	 * @param employment
	 */
	public void deleteEmployment(int id) {
		
		updateDAO.execute("employment.deleteEmploymentById", id);
	}
	
	/**
	 * 验证employmentName是否重复
	 * flag: 1 追加时验证
	 * flag: 2 更新时验证
	 */
	public boolean checkEmploymentName(Employment paramEmployment, int flag) {
		
		Employment employment = queryDAO.executeForObject("employment.getEmploymentByName",
				paramEmployment.getEnterpriseName(), Employment.class);

		if (employment == null) {
			return true;
		}
		
		// 更新验证，查出来的数据是不是本身
		if (flag == 2) {
			
			if (employment.getId() == paramEmployment.getId()) {
				return true;
			}
		}
		
		return false;
	}

	public void setQueryDAO(QueryDAO queryDAO) {
		this.queryDAO = queryDAO;
	}

	public void setUpdateDAO(UpdateDAO updateDAO) {
		this.updateDAO = updateDAO;
	}
	
	
}
